<!--订单管理-课程订单-->
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>课程订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <span>订单号：<el-input size="small" style="width: 200px;" placeholder="请输入" /></span>
      <span>考证名称：<el-input size="small" style="width: 200px;" placeholder="请输入" /></span>
      <el-form-item label="下单时间：">
        <el-date-picker
          v-model="form"
          type="date"
          placeholder="选择日期"
          style="width: 200px;">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="至">
        <el-date-picker
          v-model="form"
          type="date"
          placeholder="选择日期"
          style="width: 200px;">
        </el-date-picker>
      </el-form-item>
      <br>
      <el-form-item label="订单类型：">
        <el-select size="small" v-model="formInline.parentcode" placeholder="请选择" @change="search">
          <el-option label="全部" value="ALL"></el-option>
          <el-option label="一级" value="FEIZHI"></el-option>
          <el-option label="二级" value="JIUYI"></el-option>
          <el-option label="三级" value="JINSHU"></el-option>
          <el-option label="四级" value="SULIAO"></el-option>
          <el-option label="五级" value="JIADIAN"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态：">
        <el-select size="small" v-model="formInline.parentcode" placeholder="请选择" @change="search">
          <el-option label="全部" value="ALL"></el-option>
          <el-option label="黄一" value="FEIZHI"></el-option>
          <el-option label="李一" value="JIUYI"></el-option>
          <el-option label="王一" value="JINSHU"></el-option>
          <el-option label="张一" value="SULIAO"></el-option>
          <el-option label="孙一" value="JIADIAN"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="支付状态：">
        <el-select size="small" v-model="formInline.parentcode" placeholder="请选择" @change="search">
          <!-- <el-option label="全部" value=""></el-option> -->
          <el-option label="审核中" value="FEIZHI"></el-option>
          <el-option label="已发布" value="JIUYI"></el-option>
          <el-option label="下架" value="JINSHU"></el-option>
          <!--          <el-option label="塑料类" value="SULIAO"></el-option>-->
          <!--          <el-option label="家电类" value="JIADIAN"></el-option>-->
        </el-select>
      </el-form-item>
      <el-form-item label="操作">
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="primary" icon="el-icon-search" @click="clan">重置</el-button>
        <el-button size="small" type="primary" icon="el-icon-search" @click="orderDetails">详情</el-button>
      </el-form-item>
      <br>
      <!--      <div class="addBut">-->
      <!--        <el-button size="small" type="primary" icon="el-icon-plus" @click="itemAdd('add')">添加课程</el-button>-->
      <!--        <el-button size="mini" @click="courserTable">课程表</el-button>-->
      <!--      </div>-->

    </el-form>
    <!--列表-->
    <el-table size="small" @selection-change="selectChange" :data="selectdata" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <!-- <el-table-column align="center" type="selection" width="50">
      </el-table-column> -->
      <el-table-column align="center" sortable prop="bpto_code" label="订单号" width="150">
      </el-table-column>
      <el-table-column align="center" sortable prop="bpto_desc" label="课程名称" width="250">
      </el-table-column>
      <el-table-column align="center" sortable prop="biz_type" label="课程类型" width="250">
      </el-table-column>
      <el-table-column align="center" sortable prop="bpto_payprice" label="实际金额(元)" width="200">
      </el-table-column>
      <el-table-column align="center" sortable prop="item_unit" label="购课学员" width="200">
      </el-table-column>
      <el-table-column align="center" sortable prop="bpto_publishstate" label="订单状态" width="200">
      </el-table-column>
      <el-table-column align="center" sortable prop="bpto_paystate" label="支付状态" width="200">
      </el-table-column>
      <el-table-column align="center" sortable prop="create_time" label="下单时间" width="200">
      </el-table-column>
      <el-table-column label="操作" min-width="300">
        <template v-slot="scope">
          <!--          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">发布</el-button>-->
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">查看</el-button>
<!--          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">取消订单</el-button>-->
<!--          <el-button size="mini" @click="courserTable(scope.$index, scope.row)">退款</el-button>-->
          <!--          <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑子分类界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="30%" @click='closeDialog("edit")'>
      <el-form label-width="80px" ref="editForm" :model="editForm">
        <el-form-item label="子类名称" prop="itemname">
          <el-input size="small" v-model="editForm.itemname" auto-complete="off" placeholder="请输入子分类名称"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="unitname">
          <el-input size="small" v-model="editForm.unitname" auto-complete="off" placeholder="请输入描述"  type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="价格" prop="itemprice">
          <el-input size="small" v-model="editForm.itemprice" placeholder="请输入价格"></el-input>
        </el-form-item>
        <el-form-item label="单位" prop="itemunit">
          <el-input size="small" v-model="editForm.itemunit" placeholder="请输入单位"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("edit")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>


    </el-dialog>
    <!-- 添加子分类界面 -->
    <el-dialog :title="title" :visible.sync="addFormVisible" width="30%" @click='closeDialog("add")'>
      <el-form label-width="80px" ref="editForm" :model="editForm">
        <el-form-item label="子类名称" prop="itemname">
          <el-input size="small" v-model="editForm.itemname" auto-complete="off" placeholder="请输入子分类名称"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="unitname">
          <el-input size="small" v-model="editForm.unitname" auto-complete="off" placeholder="请输入描述"  type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="价格" prop="itemprice">
          <el-input size="small" v-model="editForm.itemprice" placeholder="请输入价格"></el-input>
        </el-form-item>
        <el-form-item label="单位" prop="itemunit">
          <el-input size="small" v-model="editForm.itemunit" placeholder="请输入单位"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("add")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitAddForm('editForm')">添加</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 导入请求方法
import {  userDelete } from '../../api/userMG'
import { selectDetail, saveClassify, saveAddClassify, deleteClassify } from '../../api/basisMG'
import Pagination from '../../components/Pagination'
import {querybcorder} from "../../api/InstitutionApi";
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      title: '添加分类',
      editFormVisible: false, //控制编辑页面显示与隐藏
      addFormVisible: false,  //控制添加页面显示与隐藏
      dataAccessshow: false, //控制数据权限显示与隐藏
      unitAccessshow: false, //控制所属单位隐藏与显示
      // 编辑与添加
      editForm: {
        itemcode:'',  //子分类ID
        itemname :'',  //子分类名称
        unitname :'', ///分类称重说明
        itemprice :'', ///价格，保留2位小数点
        itemunit :'', ///分类计价单位
      },
      // 选择数据
      selectdata: [],
      // 请求分类明细数据参数
      formInline: {
        page: 1,
        limit: 10,
        deptId: '',
        userName: '',
        userMobile: '',
        parentcode: ''
      },
      // 删除子分类的id象
      deleteItemCode:{
        itemcode:''
      },
      // 分类明细数据
      itemList:[],
      // 数据权限
      UserDept: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      // 选中
      checkmenu: [],
      //参数role
      saveroleId: '',
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },

  /**
   * 数据发生改变
   */
  watch: {},

  /**
   * 创建完毕
   */
  created() {
    this.getdata()
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取数据方法
    getdata() {
      this.loading = true
      // 获取课程订单列表
      querybcorder().then(res => {
        this.loading = false
        console.log('order',res)
        this.selectdata = res.data.base_info
      })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    //搜索事件
    search() {
      // console.log('item-formInline:',this.formInline.parentcode)
      this.getdata(this.formInline.parentcode)

    },
    // 添加新课程
    itemAdd() {
      // 跳转页面的三种方式
      // 方式1：通过 path 跳转
      // this.$router.push({
      //   path: `/enterprises/EnEdit/:index`
      // });
      // 方式2：通过 name 跳转（推荐）
      // this.$router.push({
      //   name: 'enedit',
      //   params: { index: index }
      // });
      // 方式3：带查询参数（显示在URL中）
      this.$router.push({
        path: '/onlineCourse/courseEdit',
        query: ''
      });
    },

    // 订单详情跳转
    orderDetails() {
      // 跳转页面的三种方式
      // 方式1：通过 path 跳转
      // this.$router.push({
      //   path: `/enterprises/EnEdit/:index`
      // });
      // 方式2：通过 name 跳转（推荐）
      // this.$router.push({
      //   name: 'enedit',
      //   params: { index: index }
      // });
      // 方式3：带查询参数（显示在URL中）
      this.$router.push({
        path: '/order/courseDetails',
        query: ''
      });
    },

    // 跳转到新课程表
    courserTable() {
      this.$router.push({
        path: '/onlineCourse/courseTable',
        query: ''
      });
    },
    //显示编辑界面
    handleEdit: function(index, row) {
      if (row != undefined && row != 'undefined') {
        this.editFormVisible = true
        this.title = '修改分类明细'
        this.editForm.itemcode = row.item_code
        this.editForm.itemname = row.item_name
        this.editForm.unitname = row.item_unitname
        this.editForm.itemprice = row.item_source_price
        this.editForm.itemunit = row.item_unit
      } else {
        // console.log('add:',this.formInline.parentcode)
        this.addFormVisible = true
        this.title = '添加分类明细'
        this.editForm.itemcode = this.formInline.parentcode
        this.editForm.itemname = ''
        this.editForm.unitname = ''
        this.editForm.itemprice = ''
        this.editForm.itemunit = ''
      }
    },
    // 编辑提交方法
    submitForm(editData) {
      // console.log('editData',editData)
      this.$refs[editData].validate(valid => {
        if (valid) {
          // 请求方法，保存编辑的子分类
          saveClassify(this.editForm)
            .then(res => {
              this.editFormVisible = false
              this.loading = false

              if (res.data.iteminfo != '') {
                // console.log('saveclass',this.formInline)
                this.getdata(this.formInline)
                this.$message({
                  type: 'success',
                  message: '数据保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.editFormVisible = false
              this.loading = false
              this.$message.error('保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },

    // 添加新的分类明细
    submitAddForm(addData){
      this.$refs[addData].validate(valid => {
        if (valid) {
          // 请求方法，保存添加的子分类
          saveAddClassify(this.editForm)
            .then(res => {
              this.addFormVisible = false
              this.loading = false
              if (res.data != '') {
                this.getdata(this.formInline.parentcode)
                this.$message({
                  type: 'success',
                  message: '数据保存成功！'
                })
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.addFormVisible = false
              this.loading = false
              this.$message.error('保存失败，请稍后再试！')
            })
        } else {
          return false
        }
      })
    },
    // // 选择复选框事件
    selectChange(val) {
      this.selectdata = val
    },
    // 关闭编辑、添加弹出框
    closeDialog(dialog) {
      if (dialog == 'edit') {
        this.editFormVisible = false
      } else if (dialog == 'perm') {
        this.dataAccessshow = false
      } else if (dialog == 'unit') {
        this.unitAccessshow = false
      } else if (dialog == 'add'){
        this.addFormVisible = false
      }
    },
    // 删除用户
    deleteUser(index, row) {
      this.deleteItemCode.itemcode = row.item_code
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // console.log('delete-then:',this.deleteItemCode)
          // 删除
          deleteClassify(this.deleteItemCode)
            .then(res => {
              if (res.msg == '删除分类成功') {
                this.$message({
                  type: 'success',
                  message: '删除分类成功!'
                })
                this.getdata(this.formInline.parentcode)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('数据删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除！'
          })
        })
    },
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.addBut {
  margin-bottom: 10px;
}
.userRole {
  width: 100%;
}
</style>


